package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGoodsInfoDetail3Binding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.transport.GoodsInfoDetailEntity3;
import com.swgk.core.dialog.RoundCornerDialog;
import com.sgb.kjwl.viewmodel.transport.GoodsInfoDetailModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MToast;

import javax.inject.Inject;

/**
 * 找货信息详情
 */
public class GoodsInfoDetailActivity3 extends AppActivity {

    private ActivityGoodsInfoDetail3Binding binding;
    private String goodsInfoId;

    @Inject
    GoodsInfoDetailModel3 detailModel;

    public static void start(Context context,String id){
        Intent intent = new Intent(context,GoodsInfoDetailActivity3.class);
        intent.putExtra("goodsInfoId",id);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent
                .builder()
                .appComponent(appComponent)
                .transportModule(new TransportModule(GoodsInfoDetailActivity3.this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {

        binding = DataBindingUtil.setContentView(GoodsInfoDetailActivity3.this, R.layout.activity_goods_info_detail3);
        binding.include.ivBack.setOnClickListener(this);
        binding.quotedSure.setOnClickListener(this);
        binding.kefuNumber.setOnClickListener(this);
        binding.messageOrderPhone.setOnClickListener(this);

        binding.include.titleView.setText("货源详情");
    }

    @Override
    protected void init() {

        goodsInfoId = getIntent().getStringExtra("goodsInfoId");

        //获取货物详情
        detailModel.getGoodsInfoDetail(goodsInfoId);
    }

    public void getGoodsInfoDetail(GoodsInfoDetailEntity3 entity){
        binding.setViewModel(entity);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.kefu_number:
                showDialog("400-001-0051");
                break;
            case R.id.message_order_phone:
                //认证过
//                if(false){
//                    showDialog(detailModel.detailEntity.get().getContrctsNumber());
//                }else{
//                    showDialog("");
//                }
                if(!TextUtils.isEmpty(detailModel.detailEntity.get().getContrctsNumber())){
                    showDialog(detailModel.detailEntity.get().getContrctsNumber());
                }else{
                    MToast.showToast(GoodsInfoDetailActivity3.this,"空号");
                }
                break;
            case R.id.quoted_sure:
                //报价
                GoodsInfoDetailQuotedActivity3.start(GoodsInfoDetailActivity3.this,goodsInfoId);
                break;
        }
    }

    //认证dialog
    public void showDialog(String phone) {
        View view = View.inflate(this, R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失

        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_title.setVisibility(View.VISIBLE);
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        if(TextUtils.isEmpty(phone)){
            tv_title.setText("温馨提示");
            tv_message.setText("认证后可拨打电话，去认证");
        }else{
            tv_title.setText("确认呼叫");
            tv_message.setText(phone);
        }

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(TextUtils.isEmpty(phone)){
                    //去认证

                }else{
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse("tel:" + phone));
                    startActivity(intent);
                }

                roundCornerDialog.dismiss();
            }
        });

        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }
}
